package wodegua.d30_网络通信.d5_tcp_bs_线程池;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8080);

        ThreadPoolExecutor pool = new ThreadPoolExecutor(4 * 2, 4 * 2, 0, TimeUnit.SECONDS
                ,new ArrayBlockingQueue<>(100), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        while (true) {
            Socket socket = serverSocket.accept();
            System.out.println("有人上线了="+socket.getRemoteSocketAddress());

            ServerReaderRunnable r = new ServerReaderRunnable(socket);
            pool.execute(r);
        }

    }
}
